package org.wang.generalcode.modules.gen.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.wang.generalcode.modules.gen.mapper.FieldTypeMapper;
import org.wang.generalcode.modules.gen.pojo.entity.GenFieldType;
import org.wang.generalcode.modules.gen.service.FieldTypeService;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;


/**
 * 字段类型管理
 */
@Service
public class FieldTypeServiceImpl extends ServiceImpl<FieldTypeMapper, GenFieldType> implements FieldTypeService {


    @Override
    public Map<String, GenFieldType> getMap() {
        List<GenFieldType> list = baseMapper.selectList(null);
        Map<String, GenFieldType> map = new LinkedHashMap<>(list.size());
        for (GenFieldType entity : list) {
            map.put(entity.getColumnType().toLowerCase(), entity);
        }
        return map;
    }

    @Override
    public Set<String> getPackageByTableId(Long tableId) {
        Set<String> importList = baseMapper.getPackageByTableId(tableId);

        return importList.stream().filter(StrUtil::isNotBlank).collect(Collectors.toSet());
    }
}